getApp();

module.exports = {
    pauseHandle: function() {
        var t = this;
        this.trtcComponent.data.exitIMThrottle = !0, this.trtcComponent.exitRoom().then(function() {
            t.trtcComponent.data.exitIMThrottle = !1;
        });
    },
    resetHandle: function() {
        var t = this;
        t.getRoomInfo().then(function(e) {
            var n = e.data;
            "0" != n.errorno || 1 != n.data.room_status && 2 != n.data.room_status ? wx.reLaunch({
                url: "/pages/live-video/video-detail/index?roomID=" + t.data.options.room_id
            }) : t.resetFun();
        });
    },
    resetFun: function() {
        var t = this;
        this.trtcComponent.data.exitIMThrottle = !0, t.setData({
            rtcConfig: t.data.rtcConfig
        }, function() {
            t.trtcComponent.enterRoom({
                roomID: t.data.options.room_id
            }).then(function(e) {
                console.log("重新进房成功！"), t.trtcComponent.data.exitIMThrottle = !1, t.data.myConfig.enableMic ? t.trtcComponent.publishLocalAudio() : t.trtcComponent.unpublishLocalAudio(), 
                t.data.pusher.user_id === t.data.userInfo.user_id && 0 === t.trtcComponent.getRemoteUserList().filter(function(t, e) {
                    return t.hasMainVideo;
                }).length ? t.trtcComponent.publishLocalVideo() : t.trtcComponent.setViewVisible({
                    userID: t.data.userInfo.user_id,
                    streamType: "main",
                    isVisible: !1
                });
            });
        });
    },
    backPerson: function(t) {
        var e = this.data.userList.filter(function(e, n) {
            return e.user_id === t;
        });
        if (e.length) {
            var n = this.data.messageList;
            n.push(Object.assign({
                messageText: e[0].nick_name + "返回了直播间"
            }, e[0])), this.setData({
                messageList: n
            }), this.userBackFun && this.userBackFun(t);
        } else this.addOnePerson(t);
    },
    leavePerson: function(t) {
        var e = this.data.userList.filter(function(e, n) {
            return e.user_id === t;
        });
        if (e.length) {
            var n = this.data.messageList;
            n.push(Object.assign({
                messageText: e[0].nick_name + "暂时离开了直播间"
            }, e[0])), this.setData({
                messageList: n
            }), this.userLeaveFun && this.userLeaveFun(t);
        }
    }
};